﻿using System;
using System.Collections.Generic;
using System.Windows;

using Xna = Microsoft.Xna.Framework;

namespace PotatoSoft.Representation3D
{
    /* MODEL */
    public class Oct3DView
    {
        private Xna.Graphics.GraphicsDevice graphicsDevice;
        private Xna.Graphics.BasicEffect basicEffect;
        private Xna.Graphics.VertexPositionColor[] vertices;

        public void OnDeviceCreated(Xna.Graphics.GraphicsDevice graphicsDevice)
        {
            this.graphicsDevice = graphicsDevice;

            //Xna.Graphics.RasterizerState rasterizerState = new Xna.Graphics.RasterizerState();
            //rasterizerState.FillMode = Xna.Graphics.FillMode.Solid;
            //rasterizerState.CullMode = Xna.Graphics.CullMode.None;

            //this.graphicsDevice.RasterizerState = rasterizerState;

            vertices = new Xna.Graphics.VertexPositionColor[]
            {
                new Xna.Graphics.VertexPositionColor() { Position = new Xna.Vector3(1,1,0), Color = Xna.Color.Azure },
                new Xna.Graphics.VertexPositionColor() { Position = new Xna.Vector3(1,-1,0), Color = Xna.Color.Azure },
                new Xna.Graphics.VertexPositionColor() { Position = new Xna.Vector3(-1,-1,0), Color = Xna.Color.Azure },
                new Xna.Graphics.VertexPositionColor() { Position = new Xna.Vector3(1,1,0), Color = Xna.Color.Azure },
                new Xna.Graphics.VertexPositionColor() { Position = new Xna.Vector3(-1,-1,0), Color = Xna.Color.Azure },
                new Xna.Graphics.VertexPositionColor() { Position = new Xna.Vector3(-1,1,0), Color = Xna.Color.Azure }
            };

            this.basicEffect = new Xna.Graphics.BasicEffect(this.graphicsDevice);
            this.basicEffect.TextureEnabled = false;
            this.basicEffect.VertexColorEnabled = true;

            this.basicEffect.View = Xna.Matrix.Identity; ;
            this.basicEffect.Projection = Xna.Matrix.Identity;
            this.basicEffect.World = Xna.Matrix.CreateTranslation(0.0f, 0.0f, -4.0f);
        }

        /// <summary>
        /// Zmiennna tymczasowa.
        /// </summary>
        float tymczasowaZmienna = 0.0f;

        public void OnRender(Xna.Graphics.GraphicsDevice graphicsDevice)
        {
            // tutaj już zbędny jest graphicsDevice, ale może przyda się czas który minął od ostatniej klatki ? aka GameTime
            this.graphicsDevice.Clear(Xna.Color.RoyalBlue);

            // są problemy jeszcze z rozszerzaniem okna...
            basicEffect.CurrentTechnique.Passes[0].Apply();



            this.graphicsDevice.DrawUserPrimitives<Xna.Graphics.VertexPositionColor>
                (Xna.Graphics.PrimitiveType.TriangleList, vertices, 0, 2);

            //this.graphicsDevice.DrawPrimitives(Xna.Graphics.PrimitiveType.TriangleList, 0, 2);
        }
    }
}
